package com.sparkseries.controller;

import com.sparkseries.common.util.domain.Result;
import com.sparkseries.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户登录
 * TODO 添加验证码等
 */
@RestController
@RequestMapping("/login")
@Tag(name = "用户登录")
public class LoginController {
    @Resource
    private LoginService loginService;

    /**
     * 登录
     * @param username 用户名
     * @param password 密码
     * @return 默认响应类
     */
    @PostMapping
    @Operation(summary = "登录")
    @Parameter(name = "username", required = true)
    @Parameter(name = "password", required = true)
    @PreAuthorize("")
    public Result<?> login(@RequestParam("username") String username, @RequestParam("password") String password) {
        return loginService.login(username, password);
    }
}
